﻿using BullsAndCows;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;

namespace BullsAndCows.Test
{
    [TestClass()]
    public class BullsAndCowsTest
    {
        [TestMethod()]
        [DeploymentItem("BullsAndCows.exe")]
        public void CheatTest()
        {
            BullsAndCows_Accessor.Cheat();
            BullsAndCows_Accessor.Cheat();
            BullsAndCows_Accessor.Cheat();
            BullsAndCows_Accessor.Cheat();
            BullsAndCows_Accessor.Cheat();
            for (int i = 0; i < 4; i++)
            {
                Assert.AreEqual(BullsAndCows.CheatsUsed[i], true);
            }
            Assert.AreEqual(BullsAndCows.Cheats, 5);
        }

        [TestMethod()]
        [DeploymentItem("BullsAndCows.exe")]
        public void CheckForWrongCowsAndBullsTest()
        {
            BullsAndCows.NumberToGuess = new int[] { 5,2,3,4 };
            int guess = 2517;
            bool expected = false;
            bool actual;
            actual = BullsAndCows_Accessor.CheckForCowsAndBulls(guess);
            Assert.AreEqual(expected, actual);
        }

        [TestMethod()]
        [DeploymentItem("BullsAndCows.exe")]
        public void CheckForRightCowsAndBullsTest()
        {
            BullsAndCows.NumberToGuess = new int[] { 5, 2, 3, 4 };
            int guess = 5234;
            bool expected = true;
            bool actual;
            actual = BullsAndCows_Accessor.CheckForCowsAndBulls(guess);
            Assert.AreEqual(expected, actual);
        }

        [TestMethod()]
        [DeploymentItem("BullsAndCows.exe")]
        public void PrintTopTest()
        {
            BullsAndCows.ScoreBoard.Add(12, "Pesho");
            BullsAndCows.ScoreBoard.Add(2, "Pesho");
            BullsAndCows.ScoreBoard.Add(16, "Pesho");
            BullsAndCows.ScoreBoard.Add(4, "Pesho");
            BullsAndCows.ScoreBoard.Add(11, "Pesho");
            BullsAndCows.ScoreBoard.Add(7, "Pesho");
            BullsAndCows_Accessor.PrintTop();
        }

        [TestMethod()]
        [DeploymentItem("BullsAndCows.exe")]
        public void StartNewGameTest()
        {
            BullsAndCows_Accessor.StartNewGame();
            Assert.AreEqual(BullsAndCows.Attempts, 0);
            Assert.AreEqual(BullsAndCows.Cheats, 0);
            for (int i = 0; i < 4; i++)
            {
                Assert.AreEqual(BullsAndCows.CheatsUsed[i], false);
            }
        }

        [TestMethod()]
        public void RandomNumberTest()
        {
            BullsAndCows_Accessor.StartNewGame();
            int numberToGuess = BullsAndCows.NumberToGuess[0] * 1000 + BullsAndCows.NumberToGuess[1] * 100 + BullsAndCows.NumberToGuess[2] * 10 + BullsAndCows.NumberToGuess[3];
            bool actual = BullsAndCows_Accessor.CheckForCowsAndBulls(numberToGuess);
            Assert.AreEqual(true, actual);
        }

        [TestMethod()]
        public void StartCommandTest()
        {
            bool won = false;
            BullsAndCows_Accessor.ProcessCommand("restart", ref won);
            Assert.AreEqual(BullsAndCows.Attempts, 0);
            Assert.AreEqual(BullsAndCows.Cheats, 0);
            for (int i = 0; i < 4; i++)
            {
                Assert.AreEqual(BullsAndCows.CheatsUsed[i], false);
            }
        }

        [TestMethod()]
        public void ExitCommandTest()
        {
            bool won = false;
            BullsAndCows_Accessor.ProcessCommand("exit", ref won);
        }

        [TestMethod()]
        public void RightNumberCommandTest()
        {
            BullsAndCows.NumberToGuess = new int[] { 1, 2, 3, 4 };
            bool won = false;
            BullsAndCows_Accessor.ProcessCommand("1234", ref won);
            Assert.AreEqual(true, won);
        }

        [TestMethod()]
        public void FalseCommandTest()
        {
            bool won = false;
            BullsAndCows_Accessor.ProcessCommand("cheat", ref won);
        }

        [TestMethod()]
        public void HelpCommandTest()
        {
            bool won = false;
            BullsAndCows_Accessor.ProcessCommand("help", ref won);
            Assert.AreEqual(1, BullsAndCows.Cheats);
        }

        [TestMethod()]
        public void TopCommandTest()
        {
            bool won = false;
            BullsAndCows_Accessor.ProcessCommand("top", ref won);
        }

        [TestMethod()]
        public void HelpButWonCommandTest()
        {
            bool won = true;
            BullsAndCows_Accessor.ProcessCommand("help", ref won);
        }

        [TestMethod()]
        public void AddToScoreBoardTest()
        {
            BullsAndCows_Accessor.AddToScoreBoard();
        }

        [TestMethod()]
        public void AttemptsCounterTest()
        {
            int numberOfAttempts = 3;
            for (int i = 0; i < numberOfAttempts; i++)
            {
                BullsAndCows_Accessor.CheckForCowsAndBulls(1243);
            }
            Assert.AreEqual(numberOfAttempts+1, BullsAndCows.Attempts);
        }
    }
}